package com.example.ymm.modules1.service.impl.ms;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.my.ms.PmcNote;
import com.example.ymm.modules1.mapper.my.ms.PmcNoteMapper;
import com.example.ymm.modules1.service.dto.ms.PmcNoteQueryCriteria;
import com.example.ymm.modules1.service.ms.PmcNoteService;
import com.example.ymm.util.QueryHelpPlus;
import com.example.ymm.util.UtilValidate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@DS("slave2")
@DSTransactional
public class PmcNoteServiceImpl extends BaseServiceImpl<PmcNoteMapper, PmcNote> implements PmcNoteService {

    @Override
    public TableList<PmcNote> list(PmcNoteQueryCriteria criteria, YmPageDto pageDto) {
        IPage<PmcNote> page = new Page<PmcNote>(pageDto.getPage(),pageDto.getPageSize());
        QueryWrapper predicate = QueryHelpPlus.getPredicate(PmcNote.class, criteria);
        predicate.orderByDesc("create_time");
        baseMapper.selectPage(page, predicate);
        TableList<PmcNote> tableList=new TableList(page);
        return tableList;
    }

    public List<PmcNote> queryAll(PmcNoteQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(PmcNote.class, criteria);
        predicate.orderByDesc("create_time");
        List<PmcNote> result =baseMapper.selectList(predicate);
        return result;
    }


    @Override
    public PmcNote getBiaoShiHaoAndBuMenName(String biaoShiHao, String buMenName) {
        PmcNoteQueryCriteria criteria=new PmcNoteQueryCriteria();
        criteria.setBiaoShiHao(biaoShiHao);
        criteria.setBuMenName(buMenName);
        List<PmcNote> pmcNotes = queryAll(criteria);
        if(UtilValidate.isNotEmpty(pmcNotes)){
            return pmcNotes.get(0);
        }
        return null;
    }
}
